package com.comac.print.component.app.gatewayimpl.database.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.comac.print.component.app.common.MaterPlateCommon;
import com.comac.print.component.app.dto.MasterPlateDTO;
import com.comac.print.component.app.gatewayimpl.database.dataobject.MasterPlateDO;
import com.comac.print.component.app.qry.MasterPlateListQry;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 模板表 Mapper 接口
 * </p>
 *
 * @author yy
 * @since 2022-04-08
 */
public interface MasterPlateMapper extends BaseMapper<MasterPlateDO> {
    @Select("<script>" +
            "select " +
            "m.ID as mpId, " +
            "m.MP_NAME as mpName, " +
            "m.MP_NUMBER as mpNumber, " +
            "m.MP_VERSION as mpVersion, " +
            "m.MP_URL as mpUrl, " +
            "m.MP_STATUS as mpStatus, " +
            "m.CREATOR as creator, " +
            "m.CREATE_TIME as createTime " +
            "from " +
            "	print_masterplate m " +
            "<where> " +
            "<if test=\"qry.mpName != null and qry.mpName != ''\">" +
            "     and m.MP_NAME like concat('%',#{qry.mpName},'%')" +
            "</if>" +
            "<if test=\"qry.mpVersion != null and qry.mpVersion != ''\">" +
            "     and m.MP_VERSION = #{qry.mpVersion}" +
            "</if>" +
            "<if test=\"qry.mpId != null and qry.mpId != ''\">" +
            "     and m.ID = #{qry.mpId}" +
            "</if>" +
            "<if test=\"qry.mpNumber != null and qry.mpNumber != ''\">" +
            "     and m.MP_NUMBER like concat('%',#{qry.mpNumber},'%')" +
            "</if>" +
            "<if test=\"qry.mpStatus != null and qry.mpStatus != ''\">" +
            "     and m.MP_STATUS = #{qry.mpStatus}" +
            "</if>" +
            "   and m.DELETE_FLAG = 0 " +
            "</where> " +
            "</script>")
    Page<MasterPlateDTO> qryMasterPlateList(Page page, @Param("qry") MasterPlateListQry qry);

    @Select(
            "select " +
            "m.ID as mpId " +
            "from " +
            "	print_masterplate m " +
            "where " +
            " (m.valid_end BETWEEN DATE_FORMAT(#{qry.validStart}, '%Y-%m-%d %H:%i:%s' ) and  DATE_FORMAT(#{qry.validEnd}, '%Y-%m-%d %H:%i:%s')" +
            " or " +
            " m.valid_start BETWEEN DATE_FORMAT(#{qry.validStart}, '%Y-%m-%d %H:%i:%s' ) and  DATE_FORMAT(#{qry.validEnd}, '%Y-%m-%d %H:%i:%s') )"+
            " and m.bussiness_id = #{qry.bussinessId}\n" +
            "\tand m.system_id = #{qry.systemId}\n" +
            "\tand m.delete_flag = 0 ")
    List<MasterPlateDTO> qryMasterPlateByDate(@Param("qry") MaterPlateCommon materPlateCommon);

}
